package com.zjw.yyyy2021.mmdd0926;

import java.util.*;

/**
 * <p>TODO</p>
 *
 * @author 郑大仙丶
 * @version V1.0.0
 * @date 2021/9/26 19:11
 */
public class MMdd0926 {

    /**
     * lru design
     * @param operators int整型二维数组 the ops
     * @param k int整型 the k
     * @return int整型一维数组
     */
    public int[] LRU (int[][] operators, int k) {
        LinkedHashMap<Integer,Integer> map = new LinkedHashMap();
        List<Integer> list = new LinkedList<>();

        for (int i = 0; i < operators.length; i++) {
            int flag = operators[i][0];

            if(flag == 1) {
                if(map.containsKey(operators[i][1])){
                    map.remove(operators[i][1]);
                }else if(map.size() == k) {
                    map.remove(map.entrySet().iterator().next().getKey());
                }
                map.put(operators[i][1], operators[i][2]);
            }else{
                if(map.containsKey(operators[i][1])){
                    list.add(map.get(operators[i][1]));
                    map.put(operators[i][1],map.remove(operators[i][1]));
                }else{
                    list.add(-1);
                };

            }
        }
        int[] result = new int[list.size()];
        int i = 0;
        for (Integer integer : list) {
            result[i] = integer;
            i++;
        }
        return result;
    }

    public static void main(String[] args) {
        int[][] operators = new int[3][3];
/*

[[1,1,1],[1,2,2],[1,3,2],[2,1],[1,4,4],[2,2]],3
3-2 1-1 4-4
1,1
 */
    }
}
